﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x0200003E RID: 62
public class DemoScript : MonoBehaviour
{
	// Token: 0x0600016C RID: 364 RVA: 0x0000E2BC File Offset: 0x0000C4BC
	private void Start()
	{
		this.originalRotation = base.transform.localRotation;
		Renderer component = this.LightBulb.GetComponent<Renderer>();
		if (Application.isPlaying)
		{
			component.sharedMaterial = component.material;
		}
		this.lightBulbMaterial = component.sharedMaterial;
	}

	// Token: 0x0600016D RID: 365 RVA: 0x0000E308 File Offset: 0x0000C508
	private void Update()
	{
		this.RotateMirror();
		this.MoveLightBulb();
		this.UpdateMouseLook();
		this.UpdateMovement();
	}

	// Token: 0x0600016E RID: 366 RVA: 0x0000E322 File Offset: 0x0000C522
	public void MirrorRecursionToggled()
	{
		this.ChangeMirrorRecursion();
	}

	// Token: 0x0600016F RID: 367 RVA: 0x0000E32C File Offset: 0x0000C52C
	public void ChangeMirrorRecursion()
	{
		foreach (GameObject gameObject in this.Mirrors)
		{
			MirrorScript component = gameObject.GetComponent<MirrorScript>();
			component.MirrorRecursion = this.RecursionToggle.isOn;
		}
	}

	// Token: 0x06000170 RID: 368 RVA: 0x0000E39C File Offset: 0x0000C59C
	private void UpdateMovement()
	{
		float num = 4f * Time.deltaTime;
		if (Input.GetKey(KeyCode.W))
		{
			Camera.main.transform.Translate(0f, 0f, num);
		}
		else if (Input.GetKey(KeyCode.S))
		{
			Camera.main.transform.Translate(0f, 0f, -num);
		}
		if (Input.GetKey(KeyCode.A))
		{
			Camera.main.transform.Translate(-num, 0f, 0f);
		}
		else if (Input.GetKey(KeyCode.D))
		{
			Camera.main.transform.Translate(num, 0f, 0f);
		}
		if (Input.GetKeyDown(KeyCode.M))
		{
			this.RecursionToggle.isOn = !this.RecursionToggle.isOn;
		}
	}

	// Token: 0x06000171 RID: 369 RVA: 0x0000E480 File Offset: 0x0000C680
	private void RotateMirror()
	{
		GameObject gameObject = this.Mirrors[0];
		float num = gameObject.transform.rotation.eulerAngles.y;
		if (num > 65f && num < 100f)
		{
			this.rotationModifier = -this.rotationModifier;
			num -= 65f;
			gameObject.transform.Rotate(0f, -num, 0f);
		}
		else if (num > 100f && num < 295f)
		{
			this.rotationModifier = -this.rotationModifier;
			num = 295f - num;
			gameObject.transform.Rotate(0f, num, 0f);
		}
		else
		{
			gameObject.transform.Rotate(0f, this.rotationModifier * Time.deltaTime * 20f, 0f);
		}
	}

	// Token: 0x06000172 RID: 370 RVA: 0x0000E56C File Offset: 0x0000C76C
	private void MoveLightBulb()
	{
		float num = this.LightBulb.transform.position.x;
		if (num > 5f)
		{
			this.moveModifier = -this.moveModifier;
			num = 5f;
		}
		else if (num < -5f)
		{
			this.moveModifier = -this.moveModifier;
			num = -5f;
		}
		else
		{
			num += Time.deltaTime * this.moveModifier;
		}
		Light component = this.LightBulb.GetComponent<Light>();
		this.LightBulb.transform.position = new Vector3(num, this.LightBulb.transform.position.y, this.LightBulb.transform.position.z);
		float num2 = Mathf.Min(1f, component.intensity);
		this.lightBulbMaterial.SetColor("_EmissionColor", new Color(num2, num2, num2));
	}

	// Token: 0x06000173 RID: 371 RVA: 0x0000E668 File Offset: 0x0000C868
	private void UpdateMouseLook()
	{
		if (this.axes == DemoScript.RotationAxes.MouseXAndY)
		{
			this.rotationX += Input.GetAxis("Mouse X") * this.sensitivityX;
			this.rotationY += Input.GetAxis("Mouse Y") * this.sensitivityY;
			this.rotationX = DemoScript.ClampAngle(this.rotationX, this.minimumX, this.maximumX);
			this.rotationY = DemoScript.ClampAngle(this.rotationY, this.minimumY, this.maximumY);
			Quaternion rhs = Quaternion.AngleAxis(this.rotationX, Vector3.up);
			Quaternion rhs2 = Quaternion.AngleAxis(this.rotationY, -Vector3.right);
			base.transform.localRotation = this.originalRotation * rhs * rhs2;
		}
		else if (this.axes == DemoScript.RotationAxes.MouseX)
		{
			this.rotationX += Input.GetAxis("Mouse X") * this.sensitivityX;
			this.rotationX = DemoScript.ClampAngle(this.rotationX, this.minimumX, this.maximumX);
			Quaternion rhs3 = Quaternion.AngleAxis(this.rotationX, Vector3.up);
			base.transform.localRotation = this.originalRotation * rhs3;
		}
		else
		{
			this.rotationY += Input.GetAxis("Mouse Y") * this.sensitivityY;
			this.rotationY = DemoScript.ClampAngle(this.rotationY, this.minimumY, this.maximumY);
			Quaternion rhs4 = Quaternion.AngleAxis(-this.rotationY, Vector3.right);
			base.transform.localRotation = this.originalRotation * rhs4;
		}
	}

	// Token: 0x06000174 RID: 372 RVA: 0x0000E817 File Offset: 0x0000CA17
	public static float ClampAngle(float angle, float min, float max)
	{
		if (angle < -360f)
		{
			angle += 360f;
		}
		if (angle > 360f)
		{
			angle -= 360f;
		}
		return Mathf.Clamp(angle, min, max);
	}

	// Token: 0x04000245 RID: 581
	public List<GameObject> Mirrors;

	// Token: 0x04000246 RID: 582
	public GameObject LightBulb;

	// Token: 0x04000247 RID: 583
	public Toggle RecursionToggle;

	// Token: 0x04000248 RID: 584
	private float rotationModifier = -1f;

	// Token: 0x04000249 RID: 585
	private float moveModifier = 1f;

	// Token: 0x0400024A RID: 586
	private Material lightBulbMaterial;

	// Token: 0x0400024B RID: 587
	private DemoScript.RotationAxes axes;

	// Token: 0x0400024C RID: 588
	private float sensitivityX = 15f;

	// Token: 0x0400024D RID: 589
	private float sensitivityY = 15f;

	// Token: 0x0400024E RID: 590
	private float minimumX = -360f;

	// Token: 0x0400024F RID: 591
	private float maximumX = 360f;

	// Token: 0x04000250 RID: 592
	private float minimumY = -60f;

	// Token: 0x04000251 RID: 593
	private float maximumY = 60f;

	// Token: 0x04000252 RID: 594
	private float rotationX;

	// Token: 0x04000253 RID: 595
	private float rotationY;

	// Token: 0x04000254 RID: 596
	private Quaternion originalRotation;

	// Token: 0x0200003F RID: 63
	private enum RotationAxes
	{
		// Token: 0x04000256 RID: 598
		MouseXAndY,
		// Token: 0x04000257 RID: 599
		MouseX,
		// Token: 0x04000258 RID: 600
		MouseY
	}
}
